package cn.g31010.sip.util
{	
	import com.adobe.serialization.json.JSON;
	
	import flash.external.ExternalInterface;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	
	import mx.controls.DateField;
	import mx.utils.StringUtil;
	public class Util
	{
		public function Util()
		{
		}

	public static function toURL(url:String,target:String):void{
		var request:URLRequest = new URLRequest(url);
                navigateToURL(request,target);
	}
	public static function popPage(url:String,title:String=null,paras:String=null):void{
		 //ExternalInterface.call("window.open",url,"target="+target,'height="1024",width="768",fullscreen=true,top=0,left=0,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=no');
		 ExternalInterface.call("window.open",url,title,paras);
	}
	
	public static function reolad():void{
		 ExternalInterface.call('window.location.reload()');
	}
	
	public static function getTimeMill():Number{
		return new Date().getMilliseconds();
	}
	
	public static function parseDate(mills:Number,today:Boolean):Date{
		if(mills==0){
			return new Date();
		}
		var d:Date=new Date();
		d.setTime(mills);
		return d;
	}
	public static function getDateMills(date:Date):Number{
		return date.valueOf();
	}
	
	public static function format(mills:Number,formatString:String):String{
		var d:Date=parseDate(mills,false);
		return mx.controls.DateField.dateToString(d,formatString);
	}
	
	public static function parseStringDate(date:String,formatString:String):Date{
		return mx.controls.DateField.stringToDate(date,formatString);
	}
	public static function parseLongDate(date:String,today:Boolean):Date{
		if(date==null||StringUtil.trim(date).length==0)
		return parseDate(0,today);
		var d:Number=Number(date);
		return parseDate(d,today);
	}
	
	public static function toArrayFromJson(str:String):Array{
		return JSON.decode(str) as Array;
	}
	public static function toJsonString(ar:Array):String{
		return JSON.encode(ar);
	}
	}
}